Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/errors

Package Overview
Dependencies
Maintainers
0
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/errors

Custom error types and error factory functions

  • 2.5.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
352K
increased by0.52%
Maintainers
0
Weekly downloads
 
Created

What is @thi.ng/errors?

@thi.ng/errors is a utility library for creating and handling custom error types in JavaScript. It provides a set of predefined error classes and functions to simplify error handling and improve code readability.

What are @thi.ng/errors's main functionalities?

Custom Error Classes

This feature allows you to create and use custom error classes like IllegalArgumentError and IllegalStateError to handle specific error conditions in your code.

const { IllegalArgumentError, IllegalStateError } = require('@thi.ng/errors');

function checkAge(age) {
  if (age < 0) {
    throw new IllegalArgumentError('Age cannot be negative');
  }
  if (age > 120) {
    throw new IllegalStateError('Age seems unrealistic');
  }
  return 'Age is valid';
}

try {
  console.log(checkAge(-5));
} catch (e) {
  console.error(e.message);
}

Predefined Error Types

The package provides predefined error types like UnsupportedOperationError to handle common error scenarios in a standardized way.

const { UnsupportedOperationError } = require('@thi.ng/errors');

function notImplemented() {
  throw new UnsupportedOperationError('This operation is not supported');
}

try {
  notImplemented();
} catch (e) {
  console.error(e.message);
}

Error Wrapping

The wrapError function allows you to wrap existing errors with additional context, making it easier to debug and understand the root cause of errors.

const { wrapError } = require('@thi.ng/errors');

function riskyOperation() {
  try {
    throw new Error('Something went wrong');
  } catch (e) {
    throw wrapError(e, 'Risky operation failed');
  }
}

try {
  riskyOperation();
} catch (e) {
  console.error(e.message);
}

Other packages similar to @thi.ng/errors

Keywords

FAQs

Package last updated on 05 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc